package com.ys.controller.web.sys;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.entity.shiro.LoginUser;
import com.ys.entity.sys.ToaNotice;
import com.ys.service.sys.CommonApiService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.W;

@Controller
@RequestMapping("/web/sys/toaNotice")
public class WebToaNoticeoController {
	

	@Autowired
	private CommonApiService<ToaNotice> commonApiService;
	
	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model) throws Exception{
		
		LoginUser loginUser = ShiroUtils.getLoginUser();
		Map<String, Object> extraParam = new HashMap<String, Object>();
		extraParam.put("createUserId", loginUser.getUserId());
		extraParam.put("createUserName", loginUser.getUserName());
		
		return commonApiService.toAdd(model, new ToaNotice().setStatus(1), MenuId.TOA_Notice, extraParam, null);
	}

	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, Long id){

		Map<String, Object> extraParam = new ToaNotice()
				.setId(id)
				.clearFieldsSource()
				.addLeftJoin("TS_UserChange B ON B.Id = A.CreateChangeId")
	        	.addField("B.UserId createUserId")
	        	.addField("B.UserName createUserName")
	        	.queryFirstMap();

		try {
			return commonApiService.toEdit(model, id, new ToaNotice(), MenuId.TOA_Notice, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, "数据有误，请联系客服");
		}
	}

}
